﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_AfficheInformSetting_AddOpendBound : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.FindToAddSection();
        }
    }

    /// <summary>
    /// 查找部门信息填充树节点
    /// </summary>
    protected void FindToAddSection()
    {
        TreeNode root = new TreeNode();
        root.ImageUrl = "~/images/Section.png";
        root.Text = "所有部门";
        root.Value = "0";
        root.Target = "myFrame";
        //root.SelectAction = TreeNodeSelectAction.Expand;
        root.NavigateUrl = "SectionShowList.aspx?bs_id=" + root.Value;
        SectionServices sectionService = new SectionServices();
        List<Section> firSections = sectionService.findByBaseSectionId(0);
        foreach (Section section in firSections)
        {
            TreeNode node = new TreeNode();
            node.Text = section.SectionName;
            node.Value = section.SectionId.ToString();
            node.Target = "myFrame";
            node.NavigateUrl = "SectionShowList.aspx?bs_id=" + node.Value;
            node.ImageUrl = "~/images/Sections.png";
            NodeRecursion(node, sectionService);
            root.ChildNodes.Add(node);
        }
        this.TreeView1.Nodes.Add(root);
    }

    /// <summary>
    /// 树节点递归查询
    /// </summary>
    /// <param name="node"></param>
    /// <param name="sectionService"></param>
    protected void NodeRecursion(TreeNode node, SectionServices sectionService)
    {
        int bsid = int.Parse(node.Value);
        //node.ChildNodes.Add(new TreeNode(node.Text + "办公室", node.Value, "~/images/Section/Sections.png"));
        //node.SelectAction = TreeNodeSelectAction.Expand;
        List<Section> list = sectionService.findByBaseSectionId(bsid);
        if (list != null && list.Count > 0)
        {
            foreach (Section section in list)
            {
                TreeNode sNode = new TreeNode();
                sNode.Text = section.SectionName;
                sNode.Value = section.SectionId.ToString();
                sNode.ImageUrl = "~/images/Sections.png";
                sNode.Target = "myFrame";
                sNode.NavigateUrl = "SectionShowList.aspx?bs_id=" + sNode.Value;
                node.ChildNodes.Add(sNode);
                NodeRecursion(sNode, sectionService);
            }
        }
    }
}
